package com.example.javachatroomextend.controller;

import com.example.javachatroomextend.model.Result;
import com.example.javachatroomextend.model.TodoMessage;
import com.example.javachatroomextend.model.User;
import com.example.javachatroomextend.service.TodoMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/todo")
public class TodoMessageController {
    @Autowired
    private TodoMessageService todoMessageService;

    @GetMapping("/getTodoMessage")
    public Result<List<TodoMessage>> getTodoMessage(HttpServletRequest request) {
        HttpSession session = request.getSession(false);
        User user = (User) session.getAttribute("user");
        List<TodoMessage> ret = todoMessageService.getTodoMessage(user.getUserId());
        return Result.success(ret);
    }

    @GetMapping("/getCountByUserIdAndSessionId")
    public Result<Integer> getCountByUseridAndSessionId(Integer sessionId, HttpServletRequest request) {
        HttpSession session = request.getSession(false);
        User user = (User) session.getAttribute("user");
        Integer ret = todoMessageService.getCountByUseridAndSessionId(user.getUserId(), sessionId);
        return Result.success(ret);
    }
}
